<?php
$replacement = 'ORDER BY field1 DESC, field2 ASC';
$tests = array(
	'SELECT field1, field2, field3 FROM table INNER JOIN othertable ON(field = 1)',
	'SELECT field1, field2, field3 FROM table INNER JOIN othertable ON field = 1',
	'SELECT field FROM table',
	'SELECT field FROM table HAVING field IS NULL',
	'SELECT field2 FROM table WHERE field = "value" AND otherfield = "somevalue" AND field2 = 3',
	'SELECT fields FROM table GROUP BY fields, otherfield LIMIT 0,10',
	'SELECT field FROM table WHERE field IS NULL AND otherfield = (SELECT val FROM ot WHERE geek=programmer)',
	'SELECT field, field2, field3 FROM table, table2'		
);

$pattern = '/werkt niet/';

$i = 1;
foreach($tests as $test) {
	$result = preg_replace($pattern, $replacement, $test);
	echo 'Test: ' . $i . ' ' . (strpos('ORDER BY', $result) !== false ? 'PASS' : 'FAIL') . "\n";
	
	$i++;
}
?>
